home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 001 / piblist.arc / READLINE.PAS < prev    next >
Pascal/Delphi Source File  |  1985-03-28  |  5KB  |  135 lines

  1. (*----------------------------------------------------------------------*)
  2. (*                  Read_Line --- read line from file F                 *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE Read_Line;
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*   Procedure:   Read_Line                                             *)
  10. (*                                                                      *)
  11. (*   Purpose:     Reads next line from file F and appends it to buffer. *)
  12. (*                                                                      *)
  13. (*   Calling sequence:                                                  *)
  14. (*                                                                      *)
  15. (*      Read_Line;                                                      *)
  16. (*                                                                      *)
  17. (*   Remarks:                                                           *)
  18. (*                                                                      *)
  19. (*     If the buffer is full the first Line in the buffer               *)
  20. (*     is deleted to make room.  This operation "slides the buffer      *)
  21. (*     forward" one line on the file.  If EOF(F)  is TRUE on entry      *)
  22. (*     then no line is read, and Eof_Seen is set TRUE.  Tabs are        *)
  23. (*     expanded, if Expands_Tabs is TRUE.  If the high-order bits are   *)
  24. (*     to be stripped then the read is done character by character to   *)
  25. (*     avoid problems with "disguised" carriage returns.   On entry F   *)
  26. (*     must be positioned at EOF or at the beginning of a line.  On     *)
  27. (*     exit F is left positioned at EOF or at the beginning of the next *)
  28. (*     line.                                                            *)
  29. (*                                                                      *)
  30. (*----------------------------------------------------------------------*)
  31.  
  32. VAR
  33.    Line:    STRING[Max_String];
  34.    Inlen:   INTEGER;
  35.    c:       CHAR;
  36.    i:       INTEGER;
  37.    j:       INTEGER;
  38.    n:       INTEGER;
  39.  
  40. BEGIN (* Read_Line *)
  41.  
  42.    IF NOT EOF( F ) THEN
  43.       BEGIN
  44.                                    (* Figure position in line buffer *)
  45.          IF Last = NIL THEN
  46.             Last := First
  47.          ELSE
  48.             BEGIN
  49.                Last := Last^.Next;
  50.                IF Last = First THEN First := First^.Next
  51.             END;
  52.  
  53.          WITH Last^ DO
  54.             BEGIN
  55.                                    (* Remember line number, page number *)
  56.                                    (* of this line.                     *)
  57.                Lnum := Cur_line;
  58.                Pnum := Cur_page;
  59.                                    (* Get text of line.                 *)
  60.                                    (* If bit-stripping, check on a      *)
  61.                                    (* character by character basis for  *)
  62.                                    (* CR/LF combinations.               *)
  63.  
  64.                IF ( NOT Strip_High ) THEN
  65.                   READ( F , Txt )
  66.                ELSE
  67.                   BEGIN
  68.  
  69.                      Txt := '';
  70.  
  71.                      READ( F , C );
  72.  
  73.                      C := CHR( ORD( C ) AND $7F );
  74.  
  75.                      WHILE ( C <> CR ) DO
  76.                         BEGIN
  77.                            Txt := Txt + C;
  78.                            READ( F , C );
  79.                            C  := CHR( ORD( C ) AND $7F );
  80.                         END;
  81.  
  82.                      READ( F , C );
  83.  
  84.                   END;
  85.  
  86.                                    (* Expand tabs if requested          *)
  87.                IF Expand_Tabs THEN
  88.                   BEGIN
  89.  
  90.                      Line    := Txt;
  91.                      Txt     := '';
  92.  
  93.                      Inlen   := LENGTH( Line );
  94.  
  95.                      i := 0;
  96.                      j := 0;
  97.  
  98.                      WHILE ( j < Inlen ) AND ( i < Max_String ) DO
  99.                         BEGIN
  100.  
  101.                            j := j + 1;
  102.  
  103.                            c := Line[j];
  104.  
  105.                            IF c = tab THEN
  106.                               BEGIN
  107.  
  108.                                  n := 8 - ( i - ORD( lpt ) ) mod 8;
  109.  
  110.                                  WHILE ( i < Max_String ) AND ( n > 0 ) DO
  111.                                     BEGIN
  112.                                        i      := i + 1;
  113.                                        Txt    := Txt + ' ';
  114.                                        n      := n - 1;
  115.                                     END;
  116.  
  117.                               END
  118.                            ELSE
  119.                               Txt := Txt + c;
  120.  
  121.                         END (* While *);
  122.  
  123.                   END (* IF Expand_Tabs *);
  124.  
  125.             END  (* With Last^ *) ;
  126.  
  127.          Readln_F;
  128.  
  129.       END
  130.  
  131.    ELSE
  132.       Eof_Seen := TRUE;
  133.  
  134. END   (* Read_Line *);
  135.